package com.example.administrator.yuejian_2.fragment;


import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
<<<<<<< HEAD

import com.example.administrator.yuejian_2.R;
import com.example.administrator.yuejian_2.activity.MyPostActivity;
=======
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.yuejian_2.R;
import com.example.administrator.yuejian_2.activity.AboutActivity;
import com.example.administrator.yuejian_2.activity.CollectListActivity;
import com.example.administrator.yuejian_2.activity.MyPostActivity;
import com.example.administrator.yuejian_2.activity.OrderListActivity;
import com.example.administrator.yuejian_2.activity.UserMessageActivity;
import com.example.administrator.yuejian_2.activity.UserSettingActivity;
import com.example.administrator.yuejian_2.bean.UserDetailBean;
import com.example.administrator.yuejian_2.bean.trainorderBean;
import com.example.administrator.yuejian_2.interservice.Const;
import com.example.administrator.yuejian_2.interservice.UserDetailService;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
>>>>>>> b079ae49aea3652b48f9c84201c89333c2f216f2

/**
 * A simple {@link Fragment} subclass.
 */
public class UserFragment extends Fragment {
    private ImageButton mypost;
    private int uid;
<<<<<<< HEAD
=======
    //private ImageView userpic;
    private TextView username;
    private ImageView collect;
    private ImageView order;
    private TextView about;
    private TextView message;
    private TextView setting;
    private Context context;
>>>>>>> b079ae49aea3652b48f9c84201c89333c2f216f2


    public UserFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_user, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        SharedPreferences sharedPreferences = getActivity().getSharedPreferences("userInfo",
                Context.MODE_PRIVATE);
        uid = sharedPreferences.getInt("user_id",0);
<<<<<<< HEAD

        mypost = view.findViewById(R.id.my_post);
=======
        mypost = view.findViewById(R.id.my_post);
        //userpic = view.findViewById(R.id.user_pic);
        username = view.findViewById(R.id.user_name);
        collect = view.findViewById(R.id.my_collect);
        order = view.findViewById(R.id.my_order);
        about = view.findViewById(R.id.about);
        message = view.findViewById(R.id.message);
        setting = view.findViewById(R.id.set);

        initEvents();
        getUserDetail();



    }
    public void initEvents(){
        collect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(getActivity(), CollectListActivity.class);
                startActivity(intent);
            }
        });

        about.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //fragment跳转到activity
                Intent intent = new Intent();
                intent.setClass(getActivity(), AboutActivity.class);
                startActivity(intent);
            }
        });
        order.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(getActivity(), OrderListActivity.class);
                startActivity(intent);
            }
        });
        message.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(getActivity(), UserMessageActivity.class);
                startActivity(intent);
            }
        });
        setting.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(getActivity(), UserSettingActivity.class);
                startActivity(intent);
            }
        });
>>>>>>> b079ae49aea3652b48f9c84201c89333c2f216f2
        mypost.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getActivity(), MyPostActivity.class);
                intent.putExtra("uid",uid);
                getActivity().startActivity(intent);

            }
        });
    }
<<<<<<< HEAD
=======
    public void getUserDetail(){
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(Const.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        UserDetailService service = retrofit.create(UserDetailService.class);
        Call<UserDetailBean> call = service.detail(uid);
        call.enqueue(new Callback<UserDetailBean>() {
            @Override
            public void onResponse(Call<UserDetailBean> call, Response<UserDetailBean> response) {
                if (getActivity()!= null){
                    String i = response.body().getU_name().toString();
                    username.setText(i);
//                    String pic = response.body().getU_pic();
//                    if (!pic.equals(""))
//                        Picasso.with(context)
//                                .load("http://10.0.2.2/YueJian16/Public/clubphoto/"+pic)
//                                .into(userpic);
                }
            }

            @Override
            public void onFailure(Call<UserDetailBean> call, Throwable t) {

            }


        });
    }



>>>>>>> b079ae49aea3652b48f9c84201c89333c2f216f2
}
